<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
%>
<html>
<head>
<title>用户管理</title>
<script type="text/javascript">
	//更改已选择tr的背景色
	function chgSelectedBg(dom){
		if(dom.attr("checked")=="checked"){
			dom.parent().parent().addClass("tr_selected");
			dom.parent().parent().removeClass("tr_nomal");
        }else{
        	if(dom.parent().parent().attr('bg') == 'n'){
        		dom.parent().parent().addClass("tr_nomal");
			}
        	dom.parent().parent().removeClass("tr_selected");
        }
	}
	$(function() {
		$("input[name='checkItems']").each(function() {
			$(this).click(function(){
				chgSelectedBg($(this));
			});
		});
		//弹出提示信息
		var msg = " ${actionMessages[0]}";
		if($.trim(msg) != ''){
			$.blockUI({ 
	            message: $('div.growlUI'), 
	            fadeIn: 700, 
	            fadeOut: 700, 
	            timeout: 2000, 
	            showOverlay: false, 
	            centerY: false, 
	            css: { 
	                width: '205px', 
	                top: '200px', 
	                left: '450px', 
	                right: '10px', 
	                border: 'none', 
	                padding: '5px', 
	                backgroundColor: '#000', 
	                '-webkit-border-radius': '10px', 
	                '-moz-border-radius': '10px', 
	                opacity: .8, 
	                color: '#fff' 
	            } 
	        }); 
		}
		//全选checkbox
		$("#checkAll").click(function() {
			var status;
			if($(this).attr("checked") == 'checked'){
				status = true;
			}else{
				status = false;
			}
			$("input[name='checkItems'][type='checkbox']").each(function() {
				$(this).attr("checked",status);
				chgSelectedBg($(this));
			});
		});
		//鼠标滑过tr变色
		$('#list tr').hover( 
			function() {
				$(this).addClass("tr_on");
				$(this).removeClass("tr_nomal");
			}, function() {
				if($(this).attr('bg') == 'n'){
					$(this).addClass("tr_nomal");
				}
				$(this).removeClass("tr_on");
		});
		//添加分页功能
		$('.pagination').jqPagination({
			paged : function(page) {
				$('#pageNow').val(page);
				$('#pageForm').submit();
			},
			page_string : "{current_page} / {max_page}",
			current_page : "${page.pageNow}",
			max_page : "${page.pageCount}"
		});
		//添加删除功能
		$('#del').click(
		function() {
			var bool = false;
			var para = '';
			$("input[name='checkItems']").each(function(i) {
				if ($(this).attr("checked") == 'checked') {
					para += $(this).val() + ",";
					bool = true;
				}
			});
			if (!bool) {
				alert('请至少选择一项!');
			} else {
				if (confirm("确认要删除所选角色?")) {
					window.location.href = "<%=path%>/user/delUser.htm?checkItems=" + para.substring(0,para.length-1);
				}
			}
		});
		//添加新增功能
		$('#add').click(function(){
			window.location.href = "<%=path%>/user/pAddUser.htm";
		});
		//添加编辑功能
		$('.edit').click(function(){
			var val = $(this).attr("value");
			window.location.href = "<%=path%>/user/pEditUser.htm?user.id=" + val;
		});
		//添加配置用户角色功能
		$('.confUserRole').click(function(){
			var val = $(this).attr("value");
			window.location.href = "<%=path%>/user/pConfUserRole.htm?user.id=" + val;
		});
		//重置密码
		$('#resetPwd').click(function(){
			var bool = false;
			var para = '';
			$("input[name='checkItems']").each(function(i) {
				if ($(this).attr("checked") == 'checked') {
					para += $(this).val() + ",";
					bool = true;
				}
			});
			if (!bool) {
				alert('请至少选择一项!');
			} else {
				if (confirm("确认要重置所选用户密码为初始密码?")) {
					window.location.href = "<%=path%>/user/resetPassword.htm?checkItems=" + para.substring(0,para.length-1);
				}
			}
		});
	});
</script>
<script type="text/javascript" src="<%=path%>/js/jquery.jqpagination.min.js"></script>
</head>
<body>

	<table border="1" style="width: 100%;border-collapse:collapse;border-color: #D4D4D4;" rules="rows">
		<tr style="text-align: center;">
			<form action="<%=path%>/user/listUser.htm">
				<td style="text-align: right;">登录名:</td>
				<td style="text-align: left;"><input type="text" name="user.username" value="${user.username }"></input></td>
				<td style="text-align: right;">用户姓名:</td>
				<td style="text-align: left;"><input type="text" name="user.name" value="${user.name }"></input></td>
				<td><input type="submit" name="查询"></input></td>
			</form>
		</tr>
		<tr>
			<td colspan="4">
				<span id="add" style="cursor: pointer;padding-left: 20px;background: url(<%=path %>/images/add.png) no-repeat center left;">添加</span>
				&nbsp;&nbsp;
				<span id="del" style="cursor: pointer;padding-left: 20px;background: url(<%=path %>/images/close.png) no-repeat center left;">删除</span>
				&nbsp;&nbsp;
				<span id="resetPwd" style="cursor: pointer;padding-left: 20px;background: url(<%=path %>/images/save.gif) no-repeat center left;">重置密码</span>
			</td>
			<td>
				<div class="growlUI" style="display:none">
					<h1> ${actionMessages[0]}</h1>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="5">
				<table style="width: 100%;border: 1;border-color: #D4D4D4;">
					<thead>
						<tr style="">
							<th width="5%"><input id="checkAll" type="checkbox"></input>编号</th>
							<th>登录名</th>
							<th>用户名</th>
							<th>最后修改时间</th>
							<th>配置用户角色</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="list" style="text-align: center;">
						<c:choose>
							<c:when test="${page.resultList == null || fn:length(page.resultList) <= 0}}">
								<td colspan="5" style="text-align: center;background-color: #EEFFEE">没有相关数据</td>
							</c:when>
							<c:otherwise>
								<c:forEach items="${page.resultList }" var="res" varStatus="status">
									<tr <c:if test="${status.index%2 == 0}"> bg="n" class="tr_nomal"</c:if>>
										<td><input type="checkbox" name="checkItems" value="${res['U_ID'] }" onselect="" on></input></td>
										<td>${res['USERNAME'] }</td>
										<td>${res['NAME'] }</td>
										<td>${res['LAST_MODIFY_TIME'] }</td>
										<td><span class="confUserRole" value="${res['U_ID'] }" style="cursor: pointer;padding-left: 20px;background: url(<%=path %>/images/save.gif) no-repeat center left;">配置用户角色</span></td>
										<td><span class="edit" value="${res['U_ID'] }" style="cursor: pointer;padding-left: 20px;background: url(<%=path %>/images/save.gif) no-repeat center left;">编辑</span></td>
									</tr>
								</c:forEach>
							</c:otherwise>
						</c:choose>
					</tbody>
				</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;共&nbsp;${page.total }&nbsp;条相关数据</td>
			<td colspan="3"></td>
			<td style="text-align: right;padding-right: 30px;">
				<div class="pagination">
				    <a href="#" class="first" data-action="first">首页</a>
				    <a href="#" class="previous" data-action="previous">上一页</a>
				    <input type="text" readonly="readonly" style="width: 50px;"/>
				    <a href="#" class="next" data-action="next">下一页</a>
				    <a href="#" class="last" data-action="last">尾页</a>
				</div>
				<form id="pageForm" name="pageForm" action="<%=path%>/user/listUser.htm">
					<input type="hidden" id="pageNow" name="page.pageNow"></input>
					<input type="hidden" id="checkItems" name="checkItems"></input>
				</form>
			</td>
		</tr>
	</table>
</body>
</html>